﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Microsoft.ReportingServices.ReportRendering;
using System.Windows.Forms;

namespace Acsys
{
    public class Tools
    {
        public static IList GetString(IList list)
        {
            IList result = new ArrayList();
            foreach (object o in list)
            {
                result.Add(o.ToString());
            }
            return result;
        }
        public static object GetValue(IList list, string code)
        {
            foreach (object o in list)
            {
                if (o.ToString() == code)
                {
                    return o;
                }
            }
            return null;
        }
        public static string CreateFormat(int rounding)
        {
            StringBuilder dec = new StringBuilder();
            dec.Append("###,###,###,###,###,###,###,##0");
            dec.Append(".");
            for (int i = 1; i <= rounding; i++)
            {
                dec.Append("0");
            }
            return dec.ToString();
        }
        
    }
    class ListViewItemComparerAscDesc : IComparer
    {
        private int col;
       // private SortOrder order;
        public ListViewItemComparerAscDesc()
        {
            col = 0;
            //order = SortOrder.Ascending;
        }
        public ListViewItemComparerAscDesc(int column)
        {
            col = column;
            //this.order = order;
        }
        public int Compare(object x, object y)
        {
            int returnVal;
            try
            {
                System.DateTime firstDate =
                        DateTime.Parse(((ListViewItem)x).SubItems[col].Text);
                System.DateTime secondDate =
                        DateTime.Parse(((ListViewItem)y).SubItems[col].Text);
                returnVal = DateTime.Compare(firstDate, secondDate);
            }
            catch
            {
                returnVal = String.Compare(((ListViewItem)x).SubItems[col].Text,
                            ((ListViewItem)y).SubItems[col].Text);
            }
            if (((ListViewItem)x).ListView.Sorting == SortOrder.Descending)
                returnVal *= -1;
            return returnVal;
        }
    }
}
